<jsp:include page="logincheck.jsp" />
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ page import="java.util.*" %>

<jsp:useBean id="phoneAccount" class="se2.PhoneAccount" scope="request"/>
<jsp:setProperty name="phoneAccount" property="*"/>

<jsp:useBean id="cust" class="se2.Customer" scope="request"/>
<jsp:setProperty name="cust" property="*"/>

<%
	phoneAccount.setCustomerId(Integer.valueOf(request.getParameter("id")));
	//phoneAccount = new PhoneAccount(Integer.valueOf(request.getParameter("id")));
	//cust.setId(Integer.valueOf(request.getParameter("id")));
	//cust.getCustomerFromDB();
	cust = new se2.Customer(Integer.valueOf(request.getParameter("id")));
	
%>

<html>

	<head>
		<title>Administration Console</title>
		<link rel="stylesheet" href="default.css" type="text/css" media="screen"></link>
		<script src="sorttable.js"></script>
	</head>

	<body>
		<div id="container">
			<div id="navigation">
<p>&nbsp;</p>
<jsp:include page="navigation.jsp" />
			</div>
			
			<div id="header">				
				<img src="images/header.png" />
			</div>

			<div id="content">
<!-- Main code -->

<h1>Customer Accounts :: View Customer Details</h1>

<table width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr>
		<td colspan="3"><h2>Customer Information</h2> &nbsp;&nbsp; <a href="editCustomerAccount.jsp?id=<%= cust.getId() %>"><img src="images/edit.png" alt="Edit" title="Edit" /></a></td>
	</tr>
	<tr style="background-image: url('images/tableBackground.png');">
		<td style="background-image: url('images/tableBackground.png');" width="10">&nbsp;</td>
		<td style="background-image: url('images/tableBackground.png');" width="*"><strong>Customer ID</strong></td>
		<td style="background-image: url('images/tableBackground.png');" width="*"><%= cust.getId() %></td>
	</tr>
	<tr>
		<td width="10">&nbsp;</td>
		<td width="*"><strong>Name</strong></td>
		<td width="*"><%= cust.getName() %></td>
	</tr>
	<tr style="background-image: url('images/tableBackground.png');">
		<td style="background-image: url('images/tableBackground.png');" width="10">&nbsp;</td>
		<td style="background-image: url('images/tableBackground.png');" width="*"><strong>E-mail</strong></td>
		<td style="background-image: url('images/tableBackground.png');" width="*"><%= cust.getEmail() %></td>
	</tr>
	<tr>
		<td width="10">&nbsp;</td>
		<td width="*"><strong>Address</strong></td>
		<td width="*"><%= cust.getAddress() %></td>
	</tr>
</table>

<br><br><br>
<h2>Phone Accounts</h2>
<table class="sortable" width="100%" border="0" cellpadding="0" cellspacing="0">
	<tr style="background-image: url('images/tableBackground.png');" height="50">
		<th style="background-image: url('images/tableBackground.png');" width="*" class="sorttable_nosort tableHeader" align="center"><% if (!cust.getStatus().equals("Cancelled")) { %><a href="addPhoneAccount.jsp?id=<%= cust.getId() %>"><img src="images/add.png"></a><% } %></th>
		<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="center">Extension</th>
		<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="center">IP Address</th>
		<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="center">Permissions</th>
		<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="center">Account Status</th>
		<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="center">Phone Status</th>
		<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="center">Billing Plan</th>
		<th style="background-image: url('images/tableBackground.png');" width="*" class="tableHeader" align="center">Balance</th>
		<th style="background-image: url('images/tableBackground.png');" width="10" class="sorttable_nosort tableHeader">&nbsp;</th>
		<th style="background-image: url('images/tableBackground.png');" width="10" class="sorttable_nosort tableHeader">&nbsp;</th>
	</tr>

<% boolean odd = false; %>
<c:forEach var="pa" items="${phoneAccount.allAssocPhoneAccounts}">
	<% if (odd) { %>
		<tr style="background-image: url('images/tableBackground.png');">
	<% } else { %>
		<tr>
	<% } odd = !odd; %>
		<td><center><a href="editPhoneAccount.jsp?cid=<%= cust.getId() %>&id=${pa.id}"><img src="images/edit.png" alt="Edit" title="Edit" /></a>
		<a href="viewBill.jsp?id=${pa.id}&cid=${cust.id}"><img src="images/bills.png" alt="View Bill" title="View Bill" /></a></center></td>
		<td align="center">${pa.extension}</td>
		<td align="center">${pa.ipAddress}</td>
		<td align="center">${pa.permissionsNames}</td>
		<td align="center">${pa.accountStatus}</td>
		<td align="center">${pa.phoneStatus}</td>
		<td align="center">${pa.billingPlanName}</td>
		<td align="center">${pa.formattedBalance}</td>
		<td align="center">
		    <c:choose>
		      <c:when test="${pa.accountStatus == 'Cancelled'}">&nbsp;</c:when>
		      <c:when test="${pa.accountStatus == 'Suspended'}"><a href="phoneAccountFunctions.jsp?action=unsuspend&id=${pa.id}"><img src="images/unsuspend.png" alt="Unsuspend" title="Unsuspend" /></a></c:when>
		      <c:otherwise><a href="phoneAccountFunctions.jsp?action=suspend&id=${pa.id}"><img src="images/suspend.png" alt="Suspend" title="Suspend" /></a></c:otherwise>
    		</c:choose>
		</td>
		<td align="center"><c:if test="${pa.accountStatus!='Cancelled'}"><a href="removePhoneAccount.jsp?id=${pa.id}"><img src="images/cancel.png" alt="Cancel" title="Cancel" /></a></c:if></td>
	</tr>
</c:forEach>
</table>



<!-- Main Code -->
			</div>

			<div id="footer">
<jsp:include page="footer.jsp" />
			</div>
		</div>
	</body>

</html>